<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.1.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/hexo/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/hexo/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/hexo/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/hexo/images/logo.svg" color="#222">

<link rel="stylesheet" href="/hexo/css/main.css">


<link rel="stylesheet" href="/hexo/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"youchen12138.gitee.io","root":"/hexo/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta property="og:type" content="website">
<meta property="og:title" content="幽辰的博客">
<meta property="og:url" content="https://youchen12138.gitee.io/hexo/page/6/index.html">
<meta property="og:site_name" content="幽辰的博客">
<meta property="og:locale" content="en_US">
<meta property="article:author" content="幽辰">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://youchen12138.gitee.io/hexo/page/6/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'en'
  };
</script>

  <title>幽辰的博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/hexo/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">幽辰的博客</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/hexo/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/hexo/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>Tags<span class="badge">23</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/hexo/categories/" rel="section"><i class="fa fa-th fa-fw"></i>Categories<span class="badge">14</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/hexo/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives<span class="badge">127</span></a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-ExpansionPanel/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-ExpansionPanel/" class="post-title-link" itemprop="url">Flutter-ExpansionPanel</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:55:01 / Modified: 16:55:15" itemprop="dateCreated datePublished" datetime="2020-08-26T16:55:01+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br></pre></td><td class="code"><pre><span class="line">class ExpansionPanelItem &#123;</span><br><span class="line">  final String headerText;</span><br><span class="line">  final Widget body;</span><br><span class="line">  bool isExpanded;</span><br><span class="line"></span><br><span class="line">  ExpansionPanelItem(&#123;this.headerText, this.body, this.isExpanded&#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class ExpansionPanelDemo extends StatefulWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  _ExpansionPanelDemoState createState() &#x3D;&gt; _ExpansionPanelDemoState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class _ExpansionPanelDemoState extends State&lt;ExpansionPanelDemo&gt; &#123;</span><br><span class="line">  List&lt;ExpansionPanelItem&gt; _expansionPanelItems;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  void initState() &#123;</span><br><span class="line">    super.initState();</span><br><span class="line"></span><br><span class="line">    _expansionPanelItems &#x3D; &lt;ExpansionPanelItem&gt;[</span><br><span class="line">      ExpansionPanelItem(</span><br><span class="line">        headerText: &#39;Panel A&#39;,</span><br><span class="line">        body: Container(</span><br><span class="line">          padding: EdgeInsets.all(16),</span><br><span class="line">          width: double.infinity,</span><br><span class="line">          child: Text(&#39;Content for Panel A.&#39;),</span><br><span class="line">        ),</span><br><span class="line">        isExpanded: false,</span><br><span class="line">      ),</span><br><span class="line">      ExpansionPanelItem(</span><br><span class="line">        headerText: &#39;Panel B&#39;,</span><br><span class="line">        body: Container(</span><br><span class="line">          padding: EdgeInsets.all(16),</span><br><span class="line">          width: double.infinity,</span><br><span class="line">          child: Text(&#39;Content for Panel B.&#39;),</span><br><span class="line">        ),</span><br><span class="line">        isExpanded: false,</span><br><span class="line">      ),</span><br><span class="line">      ExpansionPanelItem(</span><br><span class="line">        headerText: &#39;Panel C&#39;,</span><br><span class="line">        body: Container(</span><br><span class="line">          padding: EdgeInsets.all(16),</span><br><span class="line">          width: double.infinity,</span><br><span class="line">          child: Text(&#39;Content for Panel C.&#39;),</span><br><span class="line">        ),</span><br><span class="line">        isExpanded: false,</span><br><span class="line">      ),</span><br><span class="line">    ];</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;ExpansionPanelDemo&#39;),</span><br><span class="line">        centerTitle: true,</span><br><span class="line">      ),</span><br><span class="line">      body: Container(</span><br><span class="line">        padding: EdgeInsets.all(16),</span><br><span class="line">        child: Column(</span><br><span class="line">          mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">          children: &lt;Widget&gt;[</span><br><span class="line">            ExpansionPanelList(</span><br><span class="line">              expansionCallback: (int panelIndex, bool isExpanded) &#123;</span><br><span class="line">                setState(() &#123;</span><br><span class="line">                  _expansionPanelItems[panelIndex].isExpanded &#x3D; !isExpanded;</span><br><span class="line">                &#125;);</span><br><span class="line">              &#125;,</span><br><span class="line">              children: _expansionPanelItems.map(</span><br><span class="line">                (ExpansionPanelItem item) &#123;</span><br><span class="line">                  return ExpansionPanel(</span><br><span class="line">                    isExpanded: item.isExpanded,</span><br><span class="line">                    body: item.body,</span><br><span class="line">                    headerBuilder: (BuildContext context, bool isExpanded) &#123;</span><br><span class="line">                      return Container(</span><br><span class="line">                        padding: EdgeInsets.all(16),</span><br><span class="line">                        child: Text(</span><br><span class="line">                          item.headerText,</span><br><span class="line">                          style: Theme.of(context).textTheme.title,</span><br><span class="line">                        ),</span><br><span class="line">                      );</span><br><span class="line">                    &#125;</span><br><span class="line">                  );</span><br><span class="line">                &#125;</span><br><span class="line">              ).toList(),</span><br><span class="line">            )</span><br><span class="line">          ],</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-13390d8e4ae0f800.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-SnackBar%EF%BC%88%E6%93%8D%E4%BD%9C%E6%8F%90%E7%A4%BA%E6%A1%86%EF%BC%89/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-SnackBar%EF%BC%88%E6%93%8D%E4%BD%9C%E6%8F%90%E7%A4%BA%E6%A1%86%EF%BC%89/" class="post-title-link" itemprop="url">Flutter-SnackBar（操作提示框）</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:54:27 / Modified: 16:54:41" itemprop="dateCreated datePublished" datetime="2020-08-26T16:54:27+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line">class SnackBarDemo extends StatefulWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  _SnackBarDemoState createState() &#x3D;&gt; _SnackBarDemoState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class _SnackBarDemoState extends State&lt;SnackBarDemo&gt; &#123;</span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;SnackBarDemo&#39;),</span><br><span class="line">      ),</span><br><span class="line">      body: Container(</span><br><span class="line">        padding: EdgeInsets.all(16),</span><br><span class="line">        child: Center(</span><br><span class="line">          child: Row(</span><br><span class="line">            mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">            children: &lt;Widget&gt;[</span><br><span class="line">              SnackButton(),</span><br><span class="line">            ],</span><br><span class="line">          ),</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class SnackButton extends StatelessWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return FlatButton(</span><br><span class="line">      child: Text(&#39;Open SnackBar&#39;),</span><br><span class="line">      onPressed: ()&#123;</span><br><span class="line">        Scaffold.of(context).showSnackBar(</span><br><span class="line">          SnackBar(</span><br><span class="line">            content: Text(&#39;Processing...&#39;),</span><br><span class="line">            action: SnackBarAction(</span><br><span class="line">              label: &#39;OK&#39;,</span><br><span class="line">              onPressed: ()&#123;&#125;,</span><br><span class="line">            ),</span><br><span class="line">          )</span><br><span class="line">        );</span><br><span class="line">      &#125;,</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-ba9fe7d49f403e52.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-BottomSheet%EF%BC%88%E5%BA%95%E9%83%A8%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3%EF%BC%89/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-BottomSheet%EF%BC%88%E5%BA%95%E9%83%A8%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3%EF%BC%89/" class="post-title-link" itemprop="url">Flutter-BottomSheet（底部滑动窗口）</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:53:48 / Modified: 16:54:04" itemprop="dateCreated datePublished" datetime="2020-08-26T16:53:48+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="BottomSheet（底部滑动窗口）"><a href="#BottomSheet（底部滑动窗口）" class="headerlink" title="BottomSheet（底部滑动窗口）"></a>BottomSheet（底部滑动窗口）</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line">class BottomSheetDemo extends StatefulWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  _BottomSheetDemoState createState() &#x3D;&gt; _BottomSheetDemoState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class _BottomSheetDemoState extends State&lt;BottomSheetDemo&gt; &#123;</span><br><span class="line">  final _bottomSheetScaffoldKey &#x3D; GlobalKey&lt;ScaffoldState&gt;();</span><br><span class="line"></span><br><span class="line">  _openBottomSheet()&#123;</span><br><span class="line">    _bottomSheetScaffoldKey</span><br><span class="line">      .currentState</span><br><span class="line">      .showBottomSheet((BuildContext context)&#123;</span><br><span class="line">        return BottomAppBar(</span><br><span class="line">          child: Container(</span><br><span class="line">            height: 90,</span><br><span class="line">            width: double.infinity,</span><br><span class="line">            padding: EdgeInsets.all(16),</span><br><span class="line">            child: Row(</span><br><span class="line">              children: &lt;Widget&gt;[</span><br><span class="line">                Icon(Icons.pause_circle_outline),</span><br><span class="line">                SizedBox(width: 16,),</span><br><span class="line">                Text(&#39;01:30 &#x2F; 03:30&#39;),</span><br><span class="line">                Expanded(</span><br><span class="line">                  child: Text(&#39;Fix you - Coldplay&#39;, textAlign: TextAlign.right,),</span><br><span class="line">                )</span><br><span class="line">              ],</span><br><span class="line">            ),</span><br><span class="line">          ),</span><br><span class="line">        );</span><br><span class="line">      &#125;);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      key: _bottomSheetScaffoldKey,</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;BottomSheetDemo&#39;),</span><br><span class="line">      ),</span><br><span class="line">      body: Container(</span><br><span class="line">        padding: EdgeInsets.all(16),</span><br><span class="line">        child: Center(</span><br><span class="line">          child: Row(</span><br><span class="line">            mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">            children: &lt;Widget&gt;[</span><br><span class="line">              FlatButton(</span><br><span class="line">                child: Text(&#39;Open BottomSheet&#39;),</span><br><span class="line">                onPressed: _openBottomSheet,</span><br><span class="line">              ),</span><br><span class="line">            ],</span><br><span class="line">          ),</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-d865277afc82cd51.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h2 id="ModalBottomSheet（对话框式底部滑动窗口）"><a href="#ModalBottomSheet（对话框式底部滑动窗口）" class="headerlink" title="ModalBottomSheet（对话框式底部滑动窗口）"></a>ModalBottomSheet（对话框式底部滑动窗口）</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line">class BottomSheetDemo extends StatefulWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  _BottomSheetDemoState createState() &#x3D;&gt; _BottomSheetDemoState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class _BottomSheetDemoState extends State&lt;BottomSheetDemo&gt; &#123;</span><br><span class="line"></span><br><span class="line">  _openModalBottomSheet()&#123;</span><br><span class="line">    showModalBottomSheet(</span><br><span class="line">      context: context,</span><br><span class="line">      builder: (BuildContext context)&#123;</span><br><span class="line">        return Container(</span><br><span class="line">          height: 200,</span><br><span class="line">          child: Column(</span><br><span class="line">            children: &lt;Widget&gt;[</span><br><span class="line">              ListTile(</span><br><span class="line">                title: Text(&#39;Option A&#39;),</span><br><span class="line">              ),</span><br><span class="line">              ListTile(</span><br><span class="line">                title: Text(&#39;Option B&#39;),</span><br><span class="line">              ),</span><br><span class="line">              ListTile(</span><br><span class="line">                title: Text(&#39;Option C&#39;),</span><br><span class="line">              ),</span><br><span class="line">            ],</span><br><span class="line">          ),</span><br><span class="line">        );</span><br><span class="line">      &#125;</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;BottomSheetDemo&#39;),</span><br><span class="line">      ),</span><br><span class="line">      body: Container(</span><br><span class="line">        padding: EdgeInsets.all(16),</span><br><span class="line">        child: Center(</span><br><span class="line">          child: Row(</span><br><span class="line">            mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">            children: &lt;Widget&gt;[</span><br><span class="line">              FlatButton(</span><br><span class="line">                child: Text(&#39;Modal BottomSheet&#39;),</span><br><span class="line">                onPressed: _openModalBottomSheet,</span><br><span class="line">              ),</span><br><span class="line">            ],</span><br><span class="line">          ),</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-59c2c4ffed0f4c6b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h2 id="BottomSheet和ModalBottomSheet的区别"><a href="#BottomSheet和ModalBottomSheet的区别" class="headerlink" title="BottomSheet和ModalBottomSheet的区别"></a>BottomSheet和ModalBottomSheet的区别</h2><p><code>BottomSheet</code>点击除滑动窗口外的空白部分并不会关闭窗口；而<code>ModalBottomSheet</code>则可以</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br></pre></td><td class="code"><pre><span class="line">class BottomSheetDemo extends StatefulWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  _BottomSheetDemoState createState() &#x3D;&gt; _BottomSheetDemoState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class _BottomSheetDemoState extends State&lt;BottomSheetDemo&gt; &#123;</span><br><span class="line">  final _bottomSheetScaffoldKey &#x3D; GlobalKey&lt;ScaffoldState&gt;();</span><br><span class="line"></span><br><span class="line">  _openBottomSheet()&#123;</span><br><span class="line">    _bottomSheetScaffoldKey</span><br><span class="line">      .currentState</span><br><span class="line">      .showBottomSheet((BuildContext context)&#123;</span><br><span class="line">        return BottomAppBar(</span><br><span class="line">          child: Container(</span><br><span class="line">            height: 90,</span><br><span class="line">            width: double.infinity,</span><br><span class="line">            padding: EdgeInsets.all(16),</span><br><span class="line">            child: Row(</span><br><span class="line">              children: &lt;Widget&gt;[</span><br><span class="line">                Icon(Icons.pause_circle_outline),</span><br><span class="line">                SizedBox(width: 16,),</span><br><span class="line">                Text(&#39;01:30 &#x2F; 03:30&#39;),</span><br><span class="line">                Expanded(</span><br><span class="line">                  child: Text(&#39;Fix you - Coldplay&#39;, textAlign: TextAlign.right,),</span><br><span class="line">                )</span><br><span class="line">              ],</span><br><span class="line">            ),</span><br><span class="line">          ),</span><br><span class="line">        );</span><br><span class="line">      &#125;);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  Future _openModalBottomSheet() async&#123;</span><br><span class="line">    final String option &#x3D; await showModalBottomSheet(</span><br><span class="line">      context: context,</span><br><span class="line">      builder: (BuildContext context)&#123;</span><br><span class="line">        return Container(</span><br><span class="line">          height: 200,</span><br><span class="line">          child: Column(</span><br><span class="line">            children: &lt;Widget&gt;[</span><br><span class="line">              ListTile(</span><br><span class="line">                title: Text(&#39;Option A&#39;),</span><br><span class="line">                onTap: ()&#123;</span><br><span class="line">                  Navigator.pop(context, &#39;A&#39;);</span><br><span class="line">                &#125;,</span><br><span class="line">              ),</span><br><span class="line">              ListTile(</span><br><span class="line">                title: Text(&#39;Option B&#39;),</span><br><span class="line">                onTap: ()&#123;</span><br><span class="line">                  Navigator.pop(context, &#39;B&#39;);</span><br><span class="line">                &#125;,</span><br><span class="line">              ),</span><br><span class="line">              ListTile(</span><br><span class="line">                title: Text(&#39;Option C&#39;),</span><br><span class="line">                onTap: ()&#123;</span><br><span class="line">                  Navigator.pop(context, &#39;C&#39;);</span><br><span class="line">                &#125;,</span><br><span class="line">              ),</span><br><span class="line">            ],</span><br><span class="line">          ),</span><br><span class="line">        );</span><br><span class="line">      &#125;</span><br><span class="line">    );</span><br><span class="line"></span><br><span class="line">    debugPrint(option);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      key: _bottomSheetScaffoldKey,</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;BottomSheetDemo&#39;),</span><br><span class="line">      ),</span><br><span class="line">      body: Container(</span><br><span class="line">        padding: EdgeInsets.all(16),</span><br><span class="line">        child: Center(</span><br><span class="line">          child: Row(</span><br><span class="line">            mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">            children: &lt;Widget&gt;[</span><br><span class="line">              FlatButton(</span><br><span class="line">                child: Text(&#39;Open BottomSheet&#39;),</span><br><span class="line">                onPressed: _openBottomSheet,</span><br><span class="line">              ),</span><br><span class="line">              FlatButton(</span><br><span class="line">                child: Text(&#39;Modal BottomSheet&#39;),</span><br><span class="line">                onPressed: _openModalBottomSheet,</span><br><span class="line">              ),</span><br><span class="line">            ],</span><br><span class="line">          ),</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-AlertDialog%EF%BC%88%E6%8F%90%E7%A4%BA%E5%AF%B9%E8%AF%9D%E6%A1%86%EF%BC%89/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-AlertDialog%EF%BC%88%E6%8F%90%E7%A4%BA%E5%AF%B9%E8%AF%9D%E6%A1%86%EF%BC%89/" class="post-title-link" itemprop="url">Flutter-AlertDialog（提示对话框）</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:53:02 / Modified: 16:53:25" itemprop="dateCreated datePublished" datetime="2020-08-26T16:53:02+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br></pre></td><td class="code"><pre><span class="line">enum Action &#123; OK, Cancel &#125;</span><br><span class="line"></span><br><span class="line">class AlertDialogDemo extends StatefulWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  _AlertDialogDemoState createState() &#x3D;&gt; _AlertDialogDemoState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class _AlertDialogDemoState extends State&lt;AlertDialogDemo&gt; &#123;</span><br><span class="line">  String _choice &#x3D; &#39;Nothing&#39;;</span><br><span class="line"></span><br><span class="line">  Future _openAlertDialog() async &#123;</span><br><span class="line">    final action &#x3D; await showDialog(</span><br><span class="line">        context: context,</span><br><span class="line">        barrierDismissible: false, &#x2F;&#x2F; 若设置为false用户不能点击空白部分来关闭对话框</span><br><span class="line">        builder: (BuildContext context) &#123;</span><br><span class="line">          return AlertDialog(</span><br><span class="line">            title: Text(&#39;AlertDialog&#39;),</span><br><span class="line">            content: Text(&#39;Are you sure about this?&#39;),</span><br><span class="line">            actions: &lt;Widget&gt;[</span><br><span class="line">              FlatButton(</span><br><span class="line">                child: Text(&#39;OK&#39;),</span><br><span class="line">                onPressed: () &#123;</span><br><span class="line">                  Navigator.pop(context, Action.OK);</span><br><span class="line">                &#125;,</span><br><span class="line">              ),</span><br><span class="line">              FlatButton(</span><br><span class="line">                child: Text(&#39;Cancel&#39;),</span><br><span class="line">                onPressed: () &#123;</span><br><span class="line">                  Navigator.pop(context, Action.Cancel);</span><br><span class="line">                &#125;,</span><br><span class="line">              )</span><br><span class="line">            ],</span><br><span class="line">          );</span><br><span class="line">        &#125;);</span><br><span class="line"></span><br><span class="line">    switch (action) &#123;</span><br><span class="line">      case Action.OK:</span><br><span class="line">        setState(() &#123;</span><br><span class="line">          _choice &#x3D; &#39;OK&#39;;</span><br><span class="line">        &#125;);</span><br><span class="line">        break;</span><br><span class="line">      case Action.Cancel:</span><br><span class="line">        setState(() &#123;</span><br><span class="line">          _choice &#x3D; &#39;Cancel&#39;;</span><br><span class="line">        &#125;);</span><br><span class="line">        break;</span><br><span class="line">      default:</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;AlertDialogDemo&#39;),</span><br><span class="line">      ),</span><br><span class="line">      body: Container(</span><br><span class="line">        padding: EdgeInsets.all(16),</span><br><span class="line">        child: Column(</span><br><span class="line">          mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">          children: &lt;Widget&gt;[</span><br><span class="line">            Text(&#39;Your choice is: $_choice&#39;),</span><br><span class="line">            SizedBox(</span><br><span class="line">              height: 16,</span><br><span class="line">            ),</span><br><span class="line">            Row(</span><br><span class="line">              mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">              children: &lt;Widget&gt;[</span><br><span class="line">                RaisedButton(</span><br><span class="line">                  child: Text(&#39;Open AlertDialog&#39;),</span><br><span class="line">                  onPressed: _openAlertDialog,</span><br><span class="line">                )</span><br><span class="line">              ],</span><br><span class="line">            )</span><br><span class="line">          ],</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-0c5196f440a92009.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-SimpleDialog%EF%BC%88%E6%98%BE%E7%A4%BA%E5%AF%B9%E8%AF%9D%E6%A1%86%EF%BC%89/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-SimpleDialog%EF%BC%88%E6%98%BE%E7%A4%BA%E5%AF%B9%E8%AF%9D%E6%A1%86%EF%BC%89/" class="post-title-link" itemprop="url">Flutter-SimpleDialog（显示对话框）</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:52:06 / Modified: 16:52:28" itemprop="dateCreated datePublished" datetime="2020-08-26T16:52:06+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br></pre></td><td class="code"><pre><span class="line">enum Option &#123; A, B, C &#125;</span><br><span class="line"></span><br><span class="line">class SimpleDialogDemo extends StatefulWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  _SimpleDialogDemoState createState() &#x3D;&gt; _SimpleDialogDemoState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class _SimpleDialogDemoState extends State&lt;SimpleDialogDemo&gt; &#123;</span><br><span class="line">  String _choice &#x3D; &#39;Nothing&#39;;</span><br><span class="line"></span><br><span class="line">  Future _openSimpleDialog() async &#123;</span><br><span class="line">    final option &#x3D; await showDialog(</span><br><span class="line">      context: context,</span><br><span class="line">      builder: (BuildContext context) &#123;</span><br><span class="line">        return SimpleDialog(</span><br><span class="line">          title: Text(&#39;SimpleDialog&#39;),</span><br><span class="line">          children: &lt;Widget&gt;[</span><br><span class="line">            SimpleDialogOption(</span><br><span class="line">              child: Text(&#39;Option A&#39;),</span><br><span class="line">              onPressed: () &#123;</span><br><span class="line">                Navigator.of(context).pop(Option.A);</span><br><span class="line">              &#125;,</span><br><span class="line">            ),</span><br><span class="line">            SimpleDialogOption(</span><br><span class="line">              child: Text(&#39;Option B&#39;),</span><br><span class="line">              onPressed: () &#123;</span><br><span class="line">                Navigator.of(context).pop(Option.B);</span><br><span class="line">              &#125;,</span><br><span class="line">            ),</span><br><span class="line">            SimpleDialogOption(</span><br><span class="line">              child: Text(&#39;Option C&#39;),</span><br><span class="line">              onPressed: () &#123;</span><br><span class="line">                Navigator.of(context).pop(Option.C);</span><br><span class="line">              &#125;,</span><br><span class="line">            ),</span><br><span class="line">          ],</span><br><span class="line">        );</span><br><span class="line">      &#125;</span><br><span class="line">    );</span><br><span class="line">    </span><br><span class="line">    switch (option) &#123;</span><br><span class="line">      case Option.A:</span><br><span class="line">        setState(() &#123;</span><br><span class="line">          _choice &#x3D; &#39;A&#39;;</span><br><span class="line">        &#125;);</span><br><span class="line">        break;</span><br><span class="line">      case Option.B:</span><br><span class="line">        setState(() &#123;</span><br><span class="line">          _choice &#x3D; &#39;B&#39;;</span><br><span class="line">        &#125;);</span><br><span class="line">        break;</span><br><span class="line">      case Option.C:</span><br><span class="line">        setState(() &#123;</span><br><span class="line">          _choice &#x3D; &#39;C&#39;;</span><br><span class="line">        &#125;);</span><br><span class="line">        break;</span><br><span class="line">      default:</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;SimpleDialogDemo&#39;),</span><br><span class="line">        elevation: 0,</span><br><span class="line">      ),</span><br><span class="line">      body: Container(</span><br><span class="line">        padding: EdgeInsets.all(16),</span><br><span class="line">        child: Column(</span><br><span class="line">          mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">          children: &lt;Widget&gt;[</span><br><span class="line">            Text(&#39;Your choice is: $_choice&#39;),</span><br><span class="line">          ],</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">      floatingActionButton: FloatingActionButton(</span><br><span class="line">        child: Icon(Icons.format_list_numbered),</span><br><span class="line">        onPressed: _openSimpleDialog,</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-45d95a2596a35010.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/16731485-c792d71f5d2a81be.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-showDatePicker%EF%BC%88%E6%97%A5%E6%9C%9F%EF%BC%89%E5%92%8C%E5%BC%95%E5%85%A5%E7%AC%AC%E4%B8%89%E6%96%B9%E5%8C%85/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-showDatePicker%EF%BC%88%E6%97%A5%E6%9C%9F%EF%BC%89%E5%92%8C%E5%BC%95%E5%85%A5%E7%AC%AC%E4%B8%89%E6%96%B9%E5%8C%85/" class="post-title-link" itemprop="url">Untitled</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2020-08-26 16:51:23" itemprop="dateCreated datePublished" datetime="2020-08-26T16:51:23+08:00">2020-08-26</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2020-08-30 19:31:43" itemprop="dateModified" datetime="2020-08-30T19:31:43+08:00">2020-08-30</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="引入第三方包（以intl为例）"><a href="#引入第三方包（以intl为例）" class="headerlink" title="引入第三方包（以intl为例）"></a>引入第三方包（以intl为例）</h2><p>首先，我们可以在这个<a target="_blank" rel="noopener" href="https://pub.dev/packages">Dart Package</a>上搜索我们想要的包，然后找到intl包。<img src="https://upload-images.jianshu.io/upload_images/16731485-1336046ed8bdbc1a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>复制<code>0.16.0</code>这个版本号，找到项目文件<code>pubspec.yaml</code>，找到以下位置<br><img src="https://upload-images.jianshu.io/upload_images/16731485-28b2a95f83e879ac.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>在<code>sdk:flutter</code>的后面加上包名称和对应的版本号，如下所示：<br><img src="https://upload-images.jianshu.io/upload_images/16731485-e52c39c59b65b92a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>再按下<code>ctrl+s</code>保存，会自动在输出（指vscode的一个界面）上运行<code>flutter packages get</code>命令，vscode会自动更新包，至此，引入第三方库就成功了</p>
<h2 id="showDatePicker（日期）"><a href="#showDatePicker（日期）" class="headerlink" title="showDatePicker（日期）"></a>showDatePicker（日期）</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">import &#39;package:flutter&#x2F;material.dart&#39;;</span><br><span class="line">import &#39;package:intl&#x2F;intl.dart&#39;; &#x2F;&#x2F; 日期第三方包</span><br><span class="line">import &#39;dart:async&#39;;</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line">class DateTimeDemo extends StatefulWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  _DateTimeDemoState createState() &#x3D;&gt; _DateTimeDemoState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class _DateTimeDemoState extends State&lt;DateTimeDemo&gt; &#123;</span><br><span class="line">  DateTime selectedDate &#x3D; DateTime.now();</span><br><span class="line">  TimeOfDay selectedTime &#x3D; TimeOfDay(hour: 9, minute: 30);</span><br><span class="line"></span><br><span class="line">  void _selectDate() async &#123;</span><br><span class="line">    final DateTime date &#x3D; await showDatePicker(</span><br><span class="line">      context: context,</span><br><span class="line">      initialDate: selectedDate, &#x2F;&#x2F; 初始日期</span><br><span class="line">      firstDate: DateTime(1900), &#x2F;&#x2F; </span><br><span class="line">      lastDate: DateTime(2100),</span><br><span class="line">    );</span><br><span class="line"></span><br><span class="line">    if (date &#x3D;&#x3D; null) &#123;</span><br><span class="line">      return;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    setState(() &#123;</span><br><span class="line">      selectedDate &#x3D; date;</span><br><span class="line">    &#125;);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;DateTimeDemo&#39;),</span><br><span class="line">        elevation: 0,</span><br><span class="line">      ),</span><br><span class="line">      body: Container(</span><br><span class="line">        padding: EdgeInsets.all(16),</span><br><span class="line">        child: Column(</span><br><span class="line">          mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">          children: &lt;Widget&gt;[</span><br><span class="line">            Row(</span><br><span class="line">              mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">              children: &lt;Widget&gt;[</span><br><span class="line">                InkWell(</span><br><span class="line">                  onTap: _selectDate,</span><br><span class="line">                  child: Row(</span><br><span class="line">                    children: &lt;Widget&gt;[</span><br><span class="line">                      Text(DateFormat.yMd().format(selectedDate)),</span><br><span class="line">                      Icon(Icons.arrow_drop_down),</span><br><span class="line">                    ],</span><br><span class="line">                  ),</span><br><span class="line">                ),</span><br><span class="line">              ],</span><br><span class="line">            )</span><br><span class="line">          ],</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-abb4091e3f148bf8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/16731485-df88c0c690a10c88.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br></pre></td><td class="code"><pre><span class="line">class DateTimeDemo extends StatefulWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  _DateTimeDemoState createState() &#x3D;&gt; _DateTimeDemoState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class _DateTimeDemoState extends State&lt;DateTimeDemo&gt; &#123;</span><br><span class="line">  DateTime selectedDate &#x3D; DateTime.now();</span><br><span class="line">  TimeOfDay selectedTime &#x3D; TimeOfDay(hour: 9, minute: 30);</span><br><span class="line"></span><br><span class="line">  void _selectDate() async &#123;</span><br><span class="line">    final DateTime date &#x3D; await showDatePicker(</span><br><span class="line">      context: context,</span><br><span class="line">      initialDate: selectedDate, &#x2F;&#x2F; 初始日期</span><br><span class="line">      firstDate: DateTime(1900),</span><br><span class="line">      lastDate: DateTime(2100),</span><br><span class="line">    );</span><br><span class="line"></span><br><span class="line">    if (date &#x3D;&#x3D; null) &#123;</span><br><span class="line">      return;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    setState(() &#123;</span><br><span class="line">      selectedDate &#x3D; date;</span><br><span class="line">    &#125;);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  _selectTime() async &#123;</span><br><span class="line">    final TimeOfDay time &#x3D; await showTimePicker(</span><br><span class="line">      context: context,</span><br><span class="line">      initialTime: selectedTime,</span><br><span class="line">    );</span><br><span class="line"></span><br><span class="line">    if (time &#x3D;&#x3D; null) &#123;</span><br><span class="line">      return;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    setState(() &#123;</span><br><span class="line">      selectedTime &#x3D; time;</span><br><span class="line">    &#125;);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;DateTimeDemo&#39;),</span><br><span class="line">        elevation: 0,</span><br><span class="line">      ),</span><br><span class="line">      body: Container(</span><br><span class="line">        padding: EdgeInsets.all(16),</span><br><span class="line">        child: Column(</span><br><span class="line">          mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">          children: &lt;Widget&gt;[</span><br><span class="line">            Row(</span><br><span class="line">              mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">              children: &lt;Widget&gt;[</span><br><span class="line">                InkWell(</span><br><span class="line">                  onTap: _selectDate,</span><br><span class="line">                  child: Row(</span><br><span class="line">                    children: &lt;Widget&gt;[</span><br><span class="line">                      Text(DateFormat.yMd().format(selectedDate)),</span><br><span class="line">                      Icon(Icons.arrow_drop_down),</span><br><span class="line">                    ],</span><br><span class="line">                  ),</span><br><span class="line">                ),</span><br><span class="line">                InkWell(</span><br><span class="line">                  onTap: _selectTime,</span><br><span class="line">                  child: Row(</span><br><span class="line">                    children: &lt;Widget&gt;[</span><br><span class="line">                      Text(selectedTime.format(context)),</span><br><span class="line">                      Icon(Icons.arrow_drop_down),</span><br><span class="line">                    ],</span><br><span class="line">                  ),</span><br><span class="line">                ),</span><br><span class="line">              ],</span><br><span class="line">            )</span><br><span class="line">          ],</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-c7a09c0d8378e8dd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-Silder/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-Silder/" class="post-title-link" itemprop="url">Flutter-Silder</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:50:23 / Modified: 16:50:32" itemprop="dateCreated datePublished" datetime="2020-08-26T16:50:23+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line">class SliderDemo extends StatefulWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  _SliderDemoState createState() &#x3D;&gt; _SliderDemoState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class _SliderDemoState extends State&lt;SliderDemo&gt; &#123;</span><br><span class="line">  double _sliderItemA &#x3D; 0;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;SilderDemo&#39;),</span><br><span class="line">        elevation: 0,</span><br><span class="line">      ),</span><br><span class="line">      body: Container(</span><br><span class="line">        padding: EdgeInsets.all(16),</span><br><span class="line">        child: Column(</span><br><span class="line">          mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">          children: &lt;Widget&gt;[</span><br><span class="line">            Row(</span><br><span class="line">              mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">              children: &lt;Widget&gt;[</span><br><span class="line">                Slider(</span><br><span class="line">                  value: _sliderItemA,</span><br><span class="line">                  onChanged: (value) &#123;</span><br><span class="line">                    setState(() &#123;</span><br><span class="line">                      _sliderItemA &#x3D; value;</span><br><span class="line">                    &#125;);</span><br><span class="line">                  &#125;,</span><br><span class="line">                  min: 0,</span><br><span class="line">                  max: 10,</span><br><span class="line">                  divisions: 10, &#x2F;&#x2F; 将滑块划分为几份</span><br><span class="line">                  label: &#39;$&#123;_sliderItemA.toInt()&#125;&#39;, &#x2F;&#x2F; 将double转换为int类型的数值，一遍label显示</span><br><span class="line">                  activeColor: Theme.of(context).accentColor,</span><br><span class="line">                  inactiveColor: Theme.of(context).accentColor.withOpacity(0.3), &#x2F;&#x2F; 未滑到的区域的颜色</span><br><span class="line">                )</span><br><span class="line">              ],</span><br><span class="line">            ),</span><br><span class="line">            SizedBox(height: 16,),</span><br><span class="line">            Text(&#39;SliderValue: $_sliderItemA&#39;),</span><br><span class="line">          ],</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-4c55a294e577f90c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-Switch%E5%92%8CSwitchListTile/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-Switch%E5%92%8CSwitchListTile/" class="post-title-link" itemprop="url">Flutter-Switch和SwitchListTile</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:49:43 / Modified: 16:50:05" itemprop="dateCreated datePublished" datetime="2020-08-26T16:49:43+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">class SwitchDemo extends StatefulWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  _SwitchDemoState createState() &#x3D;&gt; _SwitchDemoState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class _SwitchDemoState extends State&lt;SwitchDemo&gt; &#123;</span><br><span class="line">  bool _switchItemA &#x3D; false;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;checkboxDemo&#39;),</span><br><span class="line">        elevation: 0,</span><br><span class="line">      ),</span><br><span class="line">      body: Container(</span><br><span class="line">        padding: EdgeInsets.all(16),</span><br><span class="line">        child: Column(</span><br><span class="line">          mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">          children: &lt;Widget&gt;[</span><br><span class="line">            Row(</span><br><span class="line">              mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">              children: &lt;Widget&gt;[</span><br><span class="line">                Switch(</span><br><span class="line">                  value: _switchItemA,</span><br><span class="line">                  onChanged: (value) &#123;</span><br><span class="line">                    setState(() &#123;</span><br><span class="line">                      _switchItemA &#x3D; value;</span><br><span class="line">                    &#125;);</span><br><span class="line">                  &#125;,</span><br><span class="line">                )</span><br><span class="line">              ],</span><br><span class="line">            )</span><br><span class="line">          ],</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-c2e07dc3ea60498b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">class SwitchDemo extends StatefulWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  _SwitchDemoState createState() &#x3D;&gt; _SwitchDemoState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class _SwitchDemoState extends State&lt;SwitchDemo&gt; &#123;</span><br><span class="line">  bool _switchItemA &#x3D; false;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;SwitchDemo&#39;),</span><br><span class="line">        elevation: 0,</span><br><span class="line">      ),</span><br><span class="line">      body: Container(</span><br><span class="line">        padding: EdgeInsets.all(16),</span><br><span class="line">        child: Column(</span><br><span class="line">          mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">          children: &lt;Widget&gt;[</span><br><span class="line">            SwitchListTile(</span><br><span class="line">              value: _switchItemA,</span><br><span class="line">              onChanged: (value) &#123;</span><br><span class="line">                setState(() &#123;</span><br><span class="line">                  _switchItemA &#x3D; value;</span><br><span class="line">                &#125;);</span><br><span class="line">              &#125;,</span><br><span class="line">              title: Text(&#39;Switch Item A&#39;),</span><br><span class="line">              subtitle: Text(&#39;Description&#39;),</span><br><span class="line">              secondary: Icon(_switchItemA ? Icons.visibility : Icons.visibility_off),</span><br><span class="line">              selected: _switchItemA,</span><br><span class="line">            ),</span><br><span class="line">            </span><br><span class="line">          ],</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-089bf5558448788a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-Radio%E4%B8%8ERadioListTile/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-Radio%E4%B8%8ERadioListTile/" class="post-title-link" itemprop="url">Flutter-Radio与RadioListTile</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:49:01 / Modified: 16:49:21" itemprop="dateCreated datePublished" datetime="2020-08-26T16:49:01+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line">class RadioDemo extends StatefulWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  _RadioDemoState createState() &#x3D;&gt; _RadioDemoState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class _RadioDemoState extends State&lt;RadioDemo&gt; &#123;</span><br><span class="line">  int _radioGroupA &#x3D; 0;</span><br><span class="line"></span><br><span class="line">  void _handleRadioValueChanged(int value)&#123;</span><br><span class="line">    setState(() &#123;</span><br><span class="line">      _radioGroupA &#x3D; value;</span><br><span class="line">    &#125;);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;checkboxDemo&#39;),</span><br><span class="line">        elevation: 0,</span><br><span class="line">      ),</span><br><span class="line">      body: Container(</span><br><span class="line">        padding: EdgeInsets.all(16),</span><br><span class="line">        child: Column(</span><br><span class="line">          mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">          children: &lt;Widget&gt;[</span><br><span class="line">            Row(</span><br><span class="line">              mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">              children: &lt;Widget&gt;[</span><br><span class="line">                Radio(</span><br><span class="line">                  value: 0,</span><br><span class="line">                  groupValue: _radioGroupA,</span><br><span class="line">                  onChanged: _handleRadioValueChanged,</span><br><span class="line">                  activeColor: Colors.blueAccent,</span><br><span class="line">                ),</span><br><span class="line">                Radio(</span><br><span class="line">                  value: 1,</span><br><span class="line">                  groupValue: _radioGroupA,</span><br><span class="line">                  onChanged: _handleRadioValueChanged,</span><br><span class="line">                  activeColor: Colors.blueAccent,</span><br><span class="line">                ),</span><br><span class="line">              ],</span><br><span class="line">            )</span><br><span class="line">          ],</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-b9d9905c31a13247.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line">class RadioDemo extends StatefulWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  _RadioDemoState createState() &#x3D;&gt; _RadioDemoState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class _RadioDemoState extends State&lt;RadioDemo&gt; &#123;</span><br><span class="line">  int _radioGroupA &#x3D; 0;</span><br><span class="line"></span><br><span class="line">  void _handleRadioValueChanged(int value)&#123;</span><br><span class="line">    setState(() &#123;</span><br><span class="line">      _radioGroupA &#x3D; value;</span><br><span class="line">    &#125;);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;checkboxDemo&#39;),</span><br><span class="line">        elevation: 0,</span><br><span class="line">      ),</span><br><span class="line">      body: Container(</span><br><span class="line">        padding: EdgeInsets.all(16),</span><br><span class="line">        child: Column(</span><br><span class="line">          mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">          children: &lt;Widget&gt;[</span><br><span class="line">            RadioListTile(</span><br><span class="line">              value: 0,</span><br><span class="line">              groupValue: _radioGroupA,</span><br><span class="line">              onChanged: _handleRadioValueChanged,</span><br><span class="line">              title: Text(&#39;Option A&#39;),</span><br><span class="line">              subtitle: Text(&#39;Description&#39;),</span><br><span class="line">              secondary: Icon(Icons.filter_1),</span><br><span class="line">              selected: _radioGroupA &#x3D;&#x3D; 0,</span><br><span class="line">            ),</span><br><span class="line">            RadioListTile(</span><br><span class="line">              value: 1,</span><br><span class="line">              groupValue: _radioGroupA,</span><br><span class="line">              onChanged: _handleRadioValueChanged,</span><br><span class="line">              title: Text(&#39;Option B&#39;),</span><br><span class="line">              subtitle: Text(&#39;Description&#39;),</span><br><span class="line">              secondary: Icon(Icons.filter_2),</span><br><span class="line">              selected: _radioGroupA &#x3D;&#x3D; 1,</span><br><span class="line">            ),</span><br><span class="line">          ],</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-ce0a03b85a5f75f7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="en">
    <link itemprop="mainEntityOfPage" href="https://youchen12138.gitee.io/hexo/2020/08/26/Flutter-CheckBox%E4%B8%8ECheckBoxListTile/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.jpg">
      <meta itemprop="name" content="幽辰">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="幽辰的博客">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/hexo/2020/08/26/Flutter-CheckBox%E4%B8%8ECheckBoxListTile/" class="post-title-link" itemprop="url">Flutter-CheckBox与CheckBoxListTile</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-08-26 16:48:25 / Modified: 16:48:35" itemprop="dateCreated datePublished" datetime="2020-08-26T16:48:25+08:00">2020-08-26</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>单独一个复选框（CheckBox）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">class CheckboxDemo extends StatefulWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  _CheckboxDemoState createState() &#x3D;&gt; _CheckboxDemoState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class _CheckboxDemoState extends State&lt;CheckboxDemo&gt; &#123;</span><br><span class="line">  bool _checkboxItemA &#x3D; true;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;checkboxDemo&#39;),</span><br><span class="line">        elevation: 0,</span><br><span class="line">      ),</span><br><span class="line">      body: Container(</span><br><span class="line">        padding: EdgeInsets.all(16),</span><br><span class="line">        child: Column(</span><br><span class="line">          mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">          children: &lt;Widget&gt;[</span><br><span class="line">            Row(</span><br><span class="line">              mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">              children: &lt;Widget&gt;[</span><br><span class="line">                Checkbox(</span><br><span class="line">                  value: _checkboxItemA,</span><br><span class="line">                  onChanged: (value) &#123;</span><br><span class="line">                    setState(() &#123;</span><br><span class="line">                      _checkboxItemA &#x3D; value;</span><br><span class="line">                    &#125;);</span><br><span class="line">                  &#125;,</span><br><span class="line">                  activeColor: Colors.green, &#x2F;&#x2F; 激活的颜色，默认为Theme的accentColor</span><br><span class="line">                ),</span><br><span class="line">              ],</span><br><span class="line">            )</span><br><span class="line">          ],</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-3340ae756f0d1023.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"><br>图标、文字和复选框（CheckBoxListTile）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">class CheckboxDemo extends StatefulWidget &#123;</span><br><span class="line">  @override</span><br><span class="line">  _CheckboxDemoState createState() &#x3D;&gt; _CheckboxDemoState();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">class _CheckboxDemoState extends State&lt;CheckboxDemo&gt; &#123;</span><br><span class="line">  bool _checkboxItemA &#x3D; true;</span><br><span class="line"></span><br><span class="line">  @override</span><br><span class="line">  Widget build(BuildContext context) &#123;</span><br><span class="line">    return Scaffold(</span><br><span class="line">      appBar: AppBar(</span><br><span class="line">        title: Text(&#39;checkboxDemo&#39;),</span><br><span class="line">        elevation: 0,</span><br><span class="line">      ),</span><br><span class="line">      body: Container(</span><br><span class="line">        padding: EdgeInsets.all(16),</span><br><span class="line">        child: Column(</span><br><span class="line">          mainAxisAlignment: MainAxisAlignment.center,</span><br><span class="line">          children: &lt;Widget&gt;[</span><br><span class="line">            CheckboxListTile(</span><br><span class="line">              value: _checkboxItemA,</span><br><span class="line">              onChanged: (value) &#123;</span><br><span class="line">                setState(() &#123;</span><br><span class="line">                  _checkboxItemA &#x3D; value;</span><br><span class="line">                &#125;);</span><br><span class="line">              &#125;,</span><br><span class="line">              title: Text(&#39;Checkbox Item A&#39;),</span><br><span class="line">              subtitle: Text(&#39;Description&#39;), &#x2F;&#x2F; 副标题</span><br><span class="line">              secondary: Icon(Icons.bookmark),</span><br><span class="line">              selected: _checkboxItemA, &#x2F;&#x2F; 设置图标和文字是否是激活状态，如果是true，则图标和文字均改变颜色</span><br><span class="line">            ),</span><br><span class="line">          ],</span><br><span class="line">        ),</span><br><span class="line">      ),</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p><img src="https://upload-images.jianshu.io/upload_images/16731485-5e843d0b1c026e17.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="预览"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/hexo/page/5/"><i class="fa fa-angle-left" aria-label="Previous page"></i></a><a class="page-number" href="/hexo/">1</a><span class="space">&hellip;</span><a class="page-number" href="/hexo/page/5/">5</a><span class="page-number current">6</span><a class="page-number" href="/hexo/page/7/">7</a><span class="space">&hellip;</span><a class="page-number" href="/hexo/page/13/">13</a><a class="extend next" rel="next" href="/hexo/page/7/"><i class="fa fa-angle-right" aria-label="Next page"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="幽辰"
      src="/hexo/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">幽辰</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/hexo/archives/">
        
          <span class="site-state-item-count">127</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/hexo/categories/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">categories</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/hexo/tags/">
          
        <span class="site-state-item-count">23</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">幽辰</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a>
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/hexo/lib/anime.min.js"></script>
  <script src="/hexo/lib/velocity/velocity.min.js"></script>
  <script src="/hexo/lib/velocity/velocity.ui.min.js"></script>

<script src="/hexo/js/utils.js"></script>

<script src="/hexo/js/motion.js"></script>


<script src="/hexo/js/schemes/pisces.js"></script>


<script src="/hexo/js/next-boot.js"></script>




  















  

  

</body>
</html>
